package geekTime.chapter23Future;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

/**
 * 线程1需要执行的任务
 * Created by LinGer on 2019/7/2
 */
public class T1Task implements Callable<String> {

    private FutureTask<String> ft2;

    /**
     * ft1任务需要ft2任务的FutureTask
     * @param ft2
     */
    public T1Task(FutureTask<String> ft2){
        this.ft2 = ft2;
    }
    @Override
    public String call() throws Exception {
        System.out.println("T1:洗水壶...1min");
        TimeUnit.SECONDS.sleep(1);

        System.out.println("T1:烧开水...15min");
        TimeUnit.SECONDS.sleep(15);

        //获取ft2的茶叶，在ft2执行完毕之前都会阻塞在此处
        String tf = ft2.get();
        System.out.println("T1:拿到茶叶 " + tf);

        System.out.println("T1:泡茶...");

        return "上茶，" + tf;
    }
}
